package software.hust.com.hust_last.util;

import android.content.Context;
import android.widget.Toast;

public class ToastUtil {
    private static Toast sToast;

    private static long sLastTime;

    private static String sLastText;

    private static final int SHORT_DELAY = 2000;

    public static void show(Context context, String text) {
        if (text == null) {
            return;
        }
        long currTime = System.currentTimeMillis();
        if (sToast == null) {
            sToast = Toast.makeText(context.getApplicationContext(), text, Toast.LENGTH_SHORT);
            sToast.show();
        } else {
            if (text.equals(sLastText)) {
                if (currTime >= sLastTime + SHORT_DELAY) {
                    sToast.show();
                } else {
                    return;
                }
            } else {
                sToast.setText(text);
                sToast.show();
            }
        }
        sLastText = text;
        sLastTime = currTime;
    }
}
